package com.aliyun.messagemgt.controller;

import com.aliyun.messagemgt.application.service.MsgSourceService;
import com.aliyun.messagemgt.application.service.OperateLogService;
import com.aliyun.messagemgt.application.service.sms.SmsQuotaConfigService;
import com.aliyun.messagemgt.application.service.sms.SmsQuotaService;
import com.aliyun.messagemgt.dto.MsgSource;
import com.aliyun.messagemgt.dto.SmsQuotaDefaultConfig;
import com.aliyun.messagemgt.dto.vo.SmsQuotaRequestVO;
import com.aliyun.messagemgt.web.controller.SmsQuotaController;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.ArrayList;

/**
 * @author wenyaxin
 * @date 2020/12/2
 */
@RunWith(MockitoJUnitRunner.class)
public class SmsQuotaControllerTest {

    @InjectMocks
    private SmsQuotaController smsQuotaController;

    @Mock
    private SmsQuotaService smsQuotaService;
    @Mock
    private SmsQuotaConfigService smsQuotaConfigService;
    @Mock
    private OperateLogService operateLogService;
    @Mock
    private MsgSourceService msgSourceService;

    @Test
    public void smsQuotaListTest(){
        Mockito.when(smsQuotaService.querySmsQuotaList(Mockito.any())).thenReturn(new PageInfo<>());
        smsQuotaController.smsQuotaList(createSmsQuotaRequestVO());
    }

    @Test
    public void smsQuotaAddTest(){
        MsgSource msgSource = new MsgSource();
        msgSource.setSourceName("1");
        msgSource.setMsgSourceId(1L);
        Mockito.when(msgSourceService.getMsgSourceBySourceId(Mockito.any())).thenReturn(msgSource);
        Mockito.when(smsQuotaService.smsQuotaAdd(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        smsQuotaController.smsQuotaAdd(createSmsQuotaRequestVO());
    }

    @Test
    public void smsQuotaConfigAddTest(){
        MsgSource msgSource = new MsgSource();
        msgSource.setSourceName("1");
        msgSource.setMsgSourceId(1L);
        Mockito.when(smsQuotaConfigService.smsQuotaConfigAdd(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        smsQuotaController.smsQuotaConfigAdd(createSmsQuotaRequestVO());
    }

    @Test
    public void smsQuotaConfigHistoryTest(){
        Mockito.when(smsQuotaConfigService.smsQuotaConfigHistory()).thenReturn(new SmsQuotaDefaultConfig());
        smsQuotaController.smsQuotaConfigHistory();
    }

    @Test
    public void smsQuotaDeptListTest(){
        Mockito.when(smsQuotaService.smsQuotaDeptList(Mockito.any())).thenReturn(new ArrayList<>());
        smsQuotaController.smsQuotaDeptList(createSmsQuotaRequestVO());
    }


    private SmsQuotaRequestVO createSmsQuotaRequestVO(){
        SmsQuotaRequestVO smsQuotaRequestVO = new SmsQuotaRequestVO();
        smsQuotaRequestVO.setUserId("1");
        smsQuotaRequestVO.setUserName("1");
        smsQuotaRequestVO.setDepartment("1");
        smsQuotaRequestVO.setDepartmentName("1");
        smsQuotaRequestVO.setMsgSourceId("1");
        return smsQuotaRequestVO;
    }

}
